import { Injectable } from '@angular/core';
import { APIBase } from 'app/modules/base/api-base';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class WarehouseService extends APIBase<any, Warehouse> {

  constructor(protected http: HttpClient) {
    super(http, '/api/admin/configs');
  }

  getAppStore() {
    return this.http.get('/api/admin/configs?group=DeepinAppStore').toPromise();
  }

  patchAppStore(data) {
    return this.http.patch('/api/admin/configs', data).toPromise();
  }

  sync() {
    return this.http.post('/api/admin/app_repository/sync', null).toPromise();
  }

  getAppStoreConfigWithKey(key) {
    return this.http.get<ResponseObj>('/api/admin/config', {
      params: {key: key}
    }).toPromise();
  }
}

export interface Warehouse {
  sys_key: string,
  sys_value: string,
  sys_group: string,
  remark: string,
  created_at: string
}

export interface ResponseObj {
  code: number;
  message: any;
}
